package net.j4love.es.example;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.junit.After;
import org.junit.Before;

import java.net.InetAddress;
import java.util.Objects;

/**
 * @author he peng
 * @create 2017/11/24 21:31
 * @see
 */
public class BaseTest {

    protected TransportClient client;

    @Before
    public void init() throws Exception {
        Settings settings = Settings.builder()
                .put("cluster.name", "my-application").build();
        this.client = new PreBuiltTransportClient(settings)
                .addTransportAddress(
                        new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
    }

    @After
    public void release() throws Exception {
        if (Objects.nonNull(this.client)) {
            this.client.close();
        }
    }
}
